package ar.com.ford.it.fullEconomics.view.action;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import org.displaytag.exception.DecoratorException;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.facade.CurrencyFacade;
import ar.com.ford.it.fullEconomics.facade.PricingFacade;
import ar.com.ford.it.fullEconomics.facade.SupplierFacade;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesm01Currency;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp01Part;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp04Supply;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp05Pricing;
import ar.com.ford.it.fullEconomics.persistence.dto.Teess01Supplier;
import ar.com.ford.it.fullEconomics.struct.OptionCombo;
import ar.com.ford.it.fullEconomics.struct.PricingStruct;
import ar.com.ford.it.fullEconomics.util.FullEconomicsDateUtil;
import ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator;
import ar.com.ford.it.fullEconomics.view.form.PricingForm;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;
import ar.com.ford.it.webengine.facade.FacadeProvider;
import ar.com.ford.it.webengine.struts.AbstractBaseAction;
import ar.com.ford.it.webengine.struts.FordActionMapping;
import ar.com.ford.it.webengine.websession.WebSession;

public class PricingAction extends AbstractBaseAction {

    public ActionForward initPage(FordActionMapping mapping,
                                  ActionForm actionForm,
                                  HttpServletRequest request,
                                  HttpServletResponse response,
                                  WebSession webSession, ActionMessages msgs,
                                  ActionMessages warns, ActionMessages errorMsgs) {

        PricingForm form = (PricingForm) actionForm;
        form.resetForm();
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        request.getSession().setAttribute("partClassColl",
                generateClassPart(request));

        request.getSession().setAttribute("partClassCollNew",
                generateClassPartNew(request));
        form.setClearParametersPanel();
        form.setModePanel("new");
        form.setPricingS(null);
        try {
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }

    private Collection<OptionCombo> generateClassPart(HttpServletRequest request) {
        Collection<OptionCombo> clasPart = new ArrayList<OptionCombo>();
        MessageResources messageResources = (MessageResources) getResources(request);
        clasPart.add(new OptionCombo("F", messageResources
                .getMessage("supply.label.optionCombo.ford")));
        clasPart.add(new OptionCombo("C", messageResources
                .getMessage("supply.label.optionCombo.custom")));
        return clasPart;
    }

    private Collection<OptionCombo> generateClassPartNew(
                                                         HttpServletRequest request) {
        Collection<OptionCombo> clasPart = new ArrayList<OptionCombo>();
        MessageResources messageResources = (MessageResources) getResources(request);
        clasPart.add(new OptionCombo("F", messageResources
                .getMessage("supply.label.optionCombo.ford")));
        clasPart.add(new OptionCombo("C", messageResources
                .getMessage("supply.label.optionCombo.custom")));
        return clasPart;
    }

    /**
     * Busca el nombre del Supplier segun el codigo ingresado (AJAX )
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward searchNameSupplier(FordActionMapping mapping,
                                            ActionForm actionForm,
                                            HttpServletRequest request,
                                            HttpServletResponse response,
                                            WebSession webSession,
                                            ActionMessages msgs,
                                            ActionMessages warns,
                                            ActionMessages errorMsgs) {
        try {
            Collection<Teess01Supplier> resultName;
            SupplierFacade facade = (SupplierFacade) FacadeProvider.getFacade(
                    request, SupplierFacade.class);
            String codeSupplier = (String) request.getParameter("supplier");
            FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                    .getUser();
            resultName = facade.findSupplier(null, codeSupplier, null, user
                    .getTeesg01Plant());
            response.setContentType("text/plain");
            if (resultName.isEmpty() || codeSupplier.equals("")) {
                response.getWriter().print("No se encontraron resultados");
            } else {
                response.getWriter().print(
                        resultName.iterator().next().getEess01SupplierNameN()
                                .toString());
            }

        } catch (FullEconomicsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * Bsuca los pricing asociado a un supply un un ragno de fechas efectivas
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward findPricing(FordActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response,
                                     WebSession webSession,
                                     ActionMessages msgs, ActionMessages warns,
                                     ActionMessages errorMsgs) {
        PricingForm form = (PricingForm) actionForm;
        Teesp05Pricing pricing = new Teesp05Pricing();
        Teesp04Supply supplyPricing = new Teesp04Supply();
        Timestamp dateEfeInSF = null;
        Timestamp dateEfeInEF = null;
        Timestamp dateEfeOutSF = null;
        Timestamp dateEfeOutEF = null;
        Calendar dateEfeInS = null;
        Calendar dateEfeInE = null;
        Calendar dateEfeOutS = null;
        Calendar dateEfeOutE = null;
        Collection<PricingStruct> resultList = null;
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        PricingFacade facadePricing = (PricingFacade) FacadeProvider.getFacade(
                request, PricingFacade.class);
        Teesp01Part partF = new Teesp01Part();
        Teess01Supplier supplierF = new Teess01Supplier();
        partF.setEesp01PlantCodeC(user.getTeesg01Plant());
        partF.setEesp01PartClassCodeC(form.getPartCF());
        partF.setEesp01PartPrefixCodeC(form.getPartPreCF());
        partF.setEesp01PartBaseCodeC(form.getPartBaseF());
        partF.setEesp01PartSuffixCodeC(form.getPartSufixF());
        supplyPricing.setTeesp01Part(partF);

        pricing.setEesp05PlantCodeC(user.getTeesg01Plant());

        supplierF.setEess01PlantCodeC(user.getTeesg01Plant());
        supplierF.setEess01SupplierCodeC(form.getSupplierCodeF());
        supplierF.setEess01SupplierClassCodeC(form.getSupplierF());
        supplyPricing.setTeess01Supplier(supplierF);
        pricing.setTeesp04Supply(supplyPricing);

        if (!form.getDateInEffStart().equals("")
                && !form.getDateInEffEnd().equals("")) {
            dateEfeInS = FullEconomicsDateUtil.format(form.getDateInEffStart());
            dateEfeInE = FullEconomicsDateUtil.format(form.getDateInEffEnd());
            dateEfeInSF = new Timestamp(dateEfeInS.getTimeInMillis());
            dateEfeInEF = new Timestamp(dateEfeInE.getTimeInMillis());

        }
        if (!form.getDateOutEffStart().equals("")
                && !form.getDateOutEffEnd().equals("")) {
            dateEfeOutS = FullEconomicsDateUtil.format(form
                    .getDateOutEffStart());
            dateEfeOutE = FullEconomicsDateUtil.format(form.getDateOutEffEnd());
            dateEfeOutSF = new Timestamp(dateEfeOutS.getTimeInMillis());
            dateEfeOutEF = new Timestamp(dateEfeOutE.getTimeInMillis());
        }
        try {
            resultList = facadePricing.findPricing(pricing, dateEfeInSF,
                    dateEfeInEF, dateEfeOutSF, dateEfeOutEF);
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        if (resultList.isEmpty()) {
            searchWithNoResults(request);
            form.setPricingS(null);
        } else {
            form.setPricingS(resultList);
        }
        
        if (form.getOperation().equals("createUpdate") &&(form.getModePanel().equals("new") || form.getModePanel().equals("edit"))){
            form.setModePanel("new");
        }
        return mapping.findForward("success");
    }

    /**
     * Crea o actualiza el Pricing
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward createUpdatePricing(FordActionMapping mapping,
                                             ActionForm actionForm,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             WebSession webSession,
                                             ActionMessages msgs,
                                             ActionMessages warns,
                                             ActionMessages errorMsgs) {
        PricingForm form = (PricingForm) actionForm;
        // Validaciones antes de crear verifico que exista la parte
        Teesp01Part part = form.getTeesp01Part();
        Teess01Supplier supplier = form.getTeess01Supplier();
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        PricingFacade facadePricing = (PricingFacade) FacadeProvider.getFacade(
                request, PricingFacade.class);
        SupplierFacade facadeSupplier = (SupplierFacade) FacadeProvider
                .getFacade(request, SupplierFacade.class);
        part.setEesp01PlantCodeC(user.getTeesg01Plant());
        CurrencyFacade facadeCurrency = (CurrencyFacade) FacadeProvider
                .getFacade(request, CurrencyFacade.class);
        supplier.setEess01PlantCodeC(user.getTeesg01Plant());
        Collection supplierS = null;
        Teesp05Pricing pricing = new Teesp05Pricing();
        Teesp01Part partF = new Teesp01Part();
        pricing.setEesp05PlantCodeC(user.getTeesg01Plant());
        pricing.setTeesp04Supply(new Teesp04Supply());

        try {
            Teesm01Currency currenNew = facadeCurrency.findCurrencyByCode(form
                    .getCurrencyNew());
            pricing.setEesp05CurrencyCodeC(currenNew);
            BigDecimal precioN = BigDecimal.valueOf(Double.valueOf(form
                    .getPriceNew()));
            Timestamp fechaIn = new Timestamp((FullEconomicsDateUtil
                    .format(form.getDateInEffStartNew())).getTimeInMillis());
            Timestamp fechaOut = null;
            if (!form.getDateOutEffEndNew().equals("")) {
                fechaOut = new Timestamp((FullEconomicsDateUtil.format(form
                        .getDateOutEffEndNew())).getTimeInMillis());
            } else {
                fechaOut = FullEconomicsDateUtil.maxDate();
            }
            if (form.getModePanel().equals("new")) {
                supplierS = facadeSupplier.findSupplier(form
                        .getTeess01Supplier().getEess01SupplierClassCodeC(),
                        form.getTeess01Supplier().getEess01SupplierCodeC(),
                        null, user.getTeesg01Plant());
                if (supplierS.isEmpty()) {
                    errorsMessage(request, "pricing.error.noSupplier");
                    return mapping.findForward("success");
                } else {
                    pricing.getTeesp04Supply().setTeess01Supplier(
                            (Teess01Supplier) supplierS.iterator().next());
                }
                // Valido la existencia del Supplier y Part ingresados
                // manualmente
                partF = facadePricing.findPart(user.getTeesg01Plant(), form
                        .getTeesp01Part().getEesp01PartClassCodeC(), form
                        .getTeesp01Part().getEesp01PartPrefixCodeC(), form
                        .getTeesp01Part().getEesp01PartBaseCodeC(), form
                        .getTeesp01Part().getEesp01PartSuffixCodeC());
                if (partF == null) {
                    errorsMessage(request, "pricing.error.noPart");
                    return mapping.findForward("success");
                } else {
                    pricing.getTeesp04Supply().setTeesp01Part(partF);
                }
                pricing.setEesp05PlantCodeC(user.getTeesg01Plant());
                pricing.getTeesp04Supply().setEesp04PlantCodeC(
                        user.getTeesg01Plant());
                // Valido qeu no exista ningun pricing en ese rango de fechas el
                // cual se quiere dar de alta
                if (facadePricing.findPricing(pricing, fechaIn, fechaOut,
                        fechaIn, fechaOut).isEmpty()) {
                    pricing.setEesp05PriceEffectiveDateY(fechaIn);
                    pricing.setEesp05PriceEndDateY(fechaOut);
                    // Verifico Existencia del Supply
                    if (facadePricing.verificSupply(pricing)) {
                        pricing.setEesp05PriceAmountA(precioN);
                        if (facadePricing.findPricingExisting(pricing, fechaIn,
                                fechaOut)) {
                            facadePricing.createPricing(pricing, user);
                        }else{
                            errorsMessage(request, "pricing.error.overloadEfectiveDate");
                            return mapping.findForward("success");
                        }
                    } else {
                        errorsMessage(request, "pricing.error.noSupply");
                        return mapping.findForward("success");
                    }
                } else {
                    errorsMessage(request, "pricing.error.overloadEfectiveDate");
                    return mapping.findForward("success");
                }

            }
            if (form.getModePanel().equals("edit")) {
                // Si modifico la fecha efectiva no sera una edicion sino un
                // alta
                if (form.getSelcetedPricing().getEesp05PriceEffectiveDateY()
                        .equals(fechaIn)) {
                    if (!facadePricing.findPricingExisting(form
                            .getSelcetedPricing(), fechaIn, fechaOut)
                            || !form.getSelcetedPricing()
                                    .getEesp05PriceEndDateY().equals(fechaOut)
                            || !form.getSelcetedPricing()
                                    .getEesp05PriceAmountA().equals(precioN)
                            || !form.getSelcetedPricing()
                                    .getEesp05CurrencyCodeC().equals(currenNew)) {
                        pricing = form.getSelcetedPricing();
                        pricing.setEesp05PriceAmountA(precioN);
                        pricing.setEesp05PriceEndDateY(fechaOut);
                        pricing.setEesp05CurrencyCodeC(facadeCurrency
                                .findCurrencyByCode(form.getCurrencyNew()));
                        facadePricing.updatePricing(pricing, user);
                    } else {
                        ActionMessages am = new ActionMessages();
                        /**/
                        return mapping.findForward("success");
                    }
                } else {
                    pricing = form.getSelcetedPricing();
                    pricing.setEesp05CurrencyCodeC(currenNew);
                    if (facadePricing.findPricingExisting(form
                            .getSelcetedPricing(), fechaIn, fechaOut)) {
                        pricing.setEesp05PriceEffectiveDateY(fechaIn);
                        pricing.setEesp05PriceEndDateY(fechaOut);
                        pricing.setEesp05PriceAmountA(precioN);
                        facadePricing.createPricing(pricing, user);
                    } else {
                        errorsMessage(request,
                                "pricing.error.overloadEfectiveDate");
                        return mapping.findForward("success");
                    }
                }
            }
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
            return mapping.findForward("success");
        }
        form.setClearParametersPanel();
        form.setModePanel("new");
        return mapping.findForward("success");

    }

    public ActionForward editSelectedPricing(FordActionMapping mapping,
                                             ActionForm actionForm,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             WebSession webSession,
                                             ActionMessages msgs,
                                             ActionMessages warns,
                                             ActionMessages errorMsgs) {

        PricingForm form = (PricingForm) actionForm;
        form.setModePanel("edit");
        form.setPricingMapped(form.getSelectedRowNum(), "");
        form.setEditParametersPanel();
        return mapping.findForward("success");
    }

    /**
     * Elimina el Pricing seleccionado
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward deletePricing(FordActionMapping mapping,
                                       ActionForm actionForm,
                                       HttpServletRequest request,
                                       HttpServletResponse response,
                                       WebSession webSession,
                                       ActionMessages msgs,
                                       ActionMessages warns,
                                       ActionMessages errorMsgs) {

        PricingForm form = (PricingForm) actionForm;
        form.setModePanel("new");
        PricingFacade facadePricing = (PricingFacade) FacadeProvider.getFacade(
                request, PricingFacade.class);
        FullEconomicsWslxUser user = (FullEconomicsWslxUser) webSession
                .getUser();
        form.setPricingMapped(form.getSelectedRowNum(), "");
        try {
            facadePricing.deletedPricing(form.getSelcetedPricing(), user);
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        form.resetPanelCreateUpdate();
        return mapping.findForward("success");
    }

    /**
     * Limpia el panel de busqueda
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward cleanFind(FordActionMapping mapping,
                                   ActionForm actionForm,
                                   HttpServletRequest request,
                                   HttpServletResponse response,
                                   WebSession webSession, ActionMessages msgs,
                                   ActionMessages warns,
                                   ActionMessages errorMsgs) {

        PricingForm form = (PricingForm) actionForm;
        form.resetPanelFind();
        return mapping.findForward("success");
    }

    /**
     * Limpia el panel de modificacion o creacion
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward cleanPanel(FordActionMapping mapping,
                                    ActionForm actionForm,
                                    HttpServletRequest request,
                                    HttpServletResponse response,
                                    WebSession webSession, ActionMessages msgs,
                                    ActionMessages warns,
                                    ActionMessages errorMsgs) {

        PricingForm form = (PricingForm) actionForm;
        form.resetPanelCreateUpdate();
        form.setModePanel("new");

        return mapping.findForward("success");
    }

    private void searchWithNoResults(HttpServletRequest request) {
        ActionMessages am = new ActionMessages();
        MessageResources messageResources = (MessageResources) getResources(request);

        am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "customMessage", messageResources
                        .getMessage("message.noResults")));
        saveMessages(request, am);
    }

    private void errorsMessage(HttpServletRequest request, String errorLabel) {
        ActionMessages am = new ActionMessages();
        MessageResources messageResources = (MessageResources) getResources(request);

        am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                "customMessage", messageResources.getMessage(errorLabel)));
        saveErrors(request, am);
    }

    /**
     * Conexion entre supply and Supplier
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward createPricingBySupply(FordActionMapping mapping,
                                               ActionForm actionForm,
                                               HttpServletRequest request,
                                               HttpServletResponse response,
                                               WebSession webSession,
                                               ActionMessages msgs,
                                               ActionMessages warns,
                                               ActionMessages errorMsgs) {
        PricingForm form = (PricingForm) actionForm;
        form.resetForm();
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        request.getSession().setAttribute("partClassColl",
                generateClassPart(request));

        request.getSession().setAttribute("partClassCollNew",
                generateClassPartNew(request));
        form.setClearParametersPanel();
        form.setModePanel("new");
        form.setTeesp01Part((Teesp01Part) request.getAttribute("partNew"));
        form.setTeess01Supplier((Teess01Supplier) request
                .getAttribute("supplierNew"));
        form.setModePanel(request.getAttribute("modePanel").toString());
        form.setSupplierCodeF(((Teess01Supplier) request
                .getAttribute("supplierNew")).getEess01SupplierCodeC());
        form.setSupplierF(((Teess01Supplier) request
                .getAttribute("supplierNew")).getEess01SupplierClassCodeC());
        form.setPartCF(form.getTeesp01Part().getEesp01PartClassCodeC());
        form.setPartPreCF(form.getTeesp01Part().getEesp01PartPrefixCodeC());
        form.setPartBaseF(form.getTeesp01Part().getEesp01PartBaseCodeC());
        form.setPartSufixF(form.getTeesp01Part().getEesp01PartSuffixCodeC());
        try {
            if (form.getModePanel().equals("edit")) {
                form.setSelcetedPricing(((Teesp05Pricing) request
                        .getAttribute("pricingSelected")));
                form.setEditParametersPanel();
            } else {
                if (form.getModePanel().equals("new")) {
                    form.setDateInEffStartNew((new DateDecorator()).decorate(
                            new Timestamp(System.currentTimeMillis()), null,
                            null).toString());
                }
            }
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        } catch (DecoratorException e) {

            e.printStackTrace();
        }
        form.setPricingS(null);
        return mapping.findForward("success");
    }

    /**
     * Bsuca los pricing asociados a una parte
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @param webSession
     * @param msgs
     * @param warns
     * @param errorMsgs
     * @return
     */
    public ActionForward findPricingByPart(FordActionMapping mapping,
                                           ActionForm actionForm,
                                           HttpServletRequest request,
                                           HttpServletResponse response,
                                           WebSession webSession,
                                           ActionMessages msgs,
                                           ActionMessages warns,
                                           ActionMessages errorMsgs) {
        PricingForm form = (PricingForm) actionForm;
        form.resetForm();
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        request.getSession().setAttribute("partClassColl",
                generateClassPart(request));
        request.getSession().setAttribute("partClassCollNew",
                generateClassPartNew(request));
        form.resetPanelFind();
        form.setModePanel("new");
        try {
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
            Teesp01Part partFind = (Teesp01Part) request
                    .getAttribute("partFind");
            form.setPartF(partFind.getEesp01PartClassCodeC().toString());
            form.setPartPreCF(partFind.getEesp01PartPrefixCodeC().toString());
            form.setPartBaseF(partFind.getEesp01PartBaseCodeC().toString());
            form.setPartSufixF(partFind.getEesp01PartSuffixCodeC().toString());
            form.setSupplierF("-1");
            form.setSupplierCodeF("");
            form.setPartCF(partFind.getEesp01PartClassCodeC().toString());
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }

    public ActionForward findPricingBySupplier(FordActionMapping mapping,
                                               ActionForm actionForm,
                                               HttpServletRequest request,
                                               HttpServletResponse response,
                                               WebSession webSession,
                                               ActionMessages msgs,
                                               ActionMessages warns,
                                               ActionMessages errorMsgs) {
        PricingForm form = (PricingForm) actionForm;
        form.resetForm();
        CurrencyFacade facadeCurr = (CurrencyFacade) FacadeProvider.getFacade(
                request, CurrencyFacade.class);
        request.getSession().setAttribute("partClassColl",
                generateClassPart(request));
        request.getSession().setAttribute("partClassCollNew",
                generateClassPartNew(request));
        form.resetPanelFind();
        form.setPricingS(null);
        form.setModePanel("new");
        try {
            request.getSession().setAttribute("economicMeasure",
                    facadeCurr.getAllCurrency());
            Teess01Supplier supplierFind = (Teess01Supplier) request
                    .getAttribute("supplierFind");
            form.setSupplierF(supplierFind.getEess01SupplierClassCodeC());
            form.setSupplierCodeF(supplierFind.getEess01SupplierCodeC());

        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }
        return mapping.findForward("success");
    }
}
